#!/bin/bash
## 生成 FaceApi cocoa client代码脚本
sh_folder=$(cd "$(dirname $0)"; pwd -P)
pushd "$sh_folder"
OUT_FOLDER=$sh_folder/src/faceapiclient.cocoa/stub
## 指定thrift compiler位置
THRIFT_EXE=
[ which thrift >/dev/null 2>&1 ] && THRIFT_EXE=$(which thrift)
[ -z "$THRIFT_EXE" ] && THRIFT_EXE=$sh_folder/dependencies/dist/thrift-$(g++ -dumpmachine)/bin/thrift
[ ! -e  $THRIFT_EXE ] && echo "not found thrift.exe,please build thrift" && exit 255

if [ -d "$OUT_FOLDER" ] ;
then
	rm  "$OUT_FOLDER"/FaceApi*.c* >/dev/null 2>&1
	rm  "$OUT_FOLDER"/FaceApi*.h* >/dev/null 2>&1
	rm  "$OUT_FOLDER"/FeatureSe*.c* >/dev/null 2>&1
	rm  "$OUT_FOLDER"/FeatureSe*.h* >/dev/null 2>&1
else
 	mkdir -p "$OUT_FOLDER" || exit
fi
$THRIFT_EXE --gen cocoa \
	-out "$OUT_FOLDER" \
	$sh_folder/../faceapi-service/FaceApi.thrift 

$THRIFT_EXE --gen cocoa \
	-out "$OUT_FOLDER" \
	$sh_folder/../faceapi-service/FeatureSe.thrift 

popd
